//
//  RXTitleView.swift
//  weibo
//
//  Created by uncle-R on 15/12/20.
//  Copyright © 2015年 uncle-R. All rights reserved.
//

import UIKit

class RXTitleView: UIButton {
    
    init(imageName:String,titleName:String){
        
        super.init(frame: CGRectZero)
        self.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        self.setTitle(titleName, forState: UIControlState.Normal)
        self.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        self.sizeToFit()

    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func layoutSubviews() {
        super.layoutSubviews()
        
        //1.将文字设置为左边
        self.titleLabel?.frame.origin.x = 0
        
        //计算文字的
 
        //2.将图片的x设置成文字的右边.左边的x 是CGFloat 必须接收一个值.
        self.imageView?.frame.origin.x = (titleLabel?.frame.size.width)!+3
    }
    
}